package entry30.pre;

import java.util.HashMap;
import java.util.Map;

public enum Operation {
	PLUS, MINUS, TIMES, DIVIDE;

	int apply(int x, int y) {
		switch (this) {
		case PLUS:
			return x + y;
		case MINUS:
			return x - y;
		case TIMES:
			return x * y;
		case DIVIDE:
			return x / y;
		}

		throw new AssertionError("Unknown op : " + this);
	}

	public static Map<String, Operation> map = new HashMap<String, Operation>();
	static {
		map.put("+", PLUS);
		map.put("-", MINUS);
		map.put("*", TIMES);
		map.put("/", DIVIDE);
	}

	public static Operation getOp(String op) {
		return map.get(op);
	}
}
